package itbour.onetouchshow.activity;

import android.animation.ValueAnimator;
import android.os.Bundle;

import com.airbnb.lottie.LottieAnimationView;

import butterknife.BindView;
import butterknife.ButterKnife;
import itbour.onetouchshow.R;
import itbour.onetouchshow.base.mvp.MVPBaseActivity;

/**
 * Created by Yang on 2017/12/16.
 */

public class BootPlayAeActivity extends MVPBaseActivity {
    @BindView(R.id.iv_mechine)
    LottieAnimationView animationView;

    @Override
    public void loadSucceed(String result) {

    }

    @Override
    public void loadFaild(String error) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_boot_play_ae;
    }

    @Override
    protected void afterCreate(Bundle savedInstanceState) {
        //   animationView.setAnimation("hello-world.json");
        //   animationView.loop(true);
        animationView.setImageAssetsFolder("botoneimage/");
        // 第一张JSON播放 自定义动画速度和时长
        ValueAnimator animator1 = ValueAnimator.ofFloat(0f, 1f)
                .setDuration(2000);
        ValueAnimator animator2 = ValueAnimator.ofFloat(0f, 1f)
                .setDuration(2000);
        animator1.addUpdateListener(animation -> {
            animationView.setProgress((Float) animation.getAnimatedValue());
            if (((Float) animation.getAnimatedValue()).intValue() == 1) {
                //播放第一张
                animationView.setAnimation("bottwo.json");
                animationView.setImageAssetsFolder("bottwoimage/");
                animationView.playAnimation();
                animator2.start();
            }
        });

        animator2.addUpdateListener(animation -> {
            animationView.setProgress((Float) animation.getAnimatedValue());
            if (((Float) animation.getAnimatedValue()).intValue() == 1) {
                openActivity(BootPageActivity.class);
                animationView.cancelAnimation();
            }
        });
        animator1.start();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }
}
